package com.zmn.plat.dubbo.impl.appointment;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
import org.apache.dubbo.config.annotation.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.plat.common.dto.appointment.AppointmentSettingDIO;
import com.zmn.plat.common.dto.appointment.AppointmentSettingDRO;
import com.zmn.plat.dubbo.interfaces.appointment.AppointmentSettingListRemoteService;
import com.zmn.plat.dubbo.utils.DubboConsts;
import com.zmn.plat.model.entity.appointment.appointmentsetting.AppointmentSettingQuery;
import com.zmn.plat.services.interfaces.appointment.appointmentsetting.AppointmentSettingService;

/**
 * 类描述：预约设置远程接口实现类
 *
 * @author xujie
 * @since 2020/09/04 10:37
 */

@Service(loadbalance = "roundrobin", timeout = 5000, version = DubboConsts.INTERFACE_VERSION, validation = "true")
public class AppointmentSettingListRemoteServiceImpl implements AppointmentSettingListRemoteService {

    private static Logger logger = LoggerFactory.getLogger(AppointmentSettingListRemoteServiceImpl.class);

    @Resource
    AppointmentSettingService appointmentSettingService;

    /**
     * 预约、改约设置查询
     *
     * @param dio
     *            预约设置AppointmentSettingDIO
     * @return 预约设置AppointmentSettingDRO集合
     */
    @Override
    @ReadOnlyConnection
    public ResponseDTO<List<AppointmentSettingDRO>> listAppointmentSettingByQuery(AppointmentSettingDIO dio) {

        try {
            AppointmentSettingQuery query = BeanMapper.map(dio, AppointmentSettingQuery.class);
            List<AppointmentSettingDRO> appointmentSettingList = Optional.ofNullable(appointmentSettingService.listByQuery(query)).orElse(Collections.emptyList()).stream()
                .map(m -> BeanMapper.map(m, AppointmentSettingDRO.class)).collect(Collectors.toList());

            return ResponseDTO.success(appointmentSettingList, "预约、改约设置查询成功");
        } catch (Exception e) {
            logger.error("预约、改约设置查询失败, e: {}, msg: {}", e, e.getMessage());
            return ResponseDTO.fail("预约、改约设置查询失败");
        }

    }
}
